<template>
	<view>
		<u-sticky>
			<view class="header">
				<u-search placeholder="请输入订单号 昵称" v-model="keyword" shape="square" :showAction="false" @search="searchlist"></u-search>
				<view class="button">
					<view class="btn" @click="show = true">{{ orderStatusName }}</view>
				</view>
			</view>
			<u-picker :show="show" :columns="orderStatusList" keyName="name" @confirm="confirm" @cancel="show = false"></u-picker>
			<view class="tags"><u-tabs :list="list1" @click="click" width="300rpx"></u-tabs></view>
		</u-sticky>
		<view class="content">
			<view class="box" v-for="item in orderList">
				<view class="" @tap="goDetail(item)">
					<view class="title">
						<view class="title-con" v-if="item.orderStatus == 0">待付款</view>
							<view class="title-con" v-else-if="item.orderStatus == 1">待接单</view>
							<view  class="title-con"v-else-if="item.orderStatus == 2">待发货</view>
							<view class="title-con" v-else-if="item.orderStatus == 3">待收货</view>
							<view class="title-con" v-else-if="item.orderStatus == 4">待使用</view>
							<view class="title-con" v-else-if="item.orderStatus == 5" style="color: #4cd909">已完成</view>
							<view class="title-con" v-else-if="item.orderStatus == 6" style="color: #606266">已取消</view>
							<view class="title-con" v-else-if="item.orderStatus == 7" style="color: #606266">已失效</view>
							<view class="title-con" v-else-if="item.orderStatus == 8">退款中</view>
							<view class="title-con" v-else-if="item.orderStatus == 9">已退款</view>
							<view  class="title-con"v-else-if="item.orderStatus == 10">未退款</view>
						</view>
					</view>
					<view class="box-con">
						<view class="box-con-left">商品合计</view>
						<view class="box-con-right">
							￥{{ item.totalMoney }}
							<!-- <text>(共一件商品)</text> -->
						</view>
					</view>
					<view class="box-con">
						<view class="box-con-left">实际支付</view>
						<view class="box-con-right">
							￥{{ item.payMoney }}
							<!-- <text>(含运费)</text> -->
						</view>
					</view>
					<view class="box-con">
						<view class="box-con-left">配送方式</view>
						<view class="box-con-right" v-if="item.logisticsType == 0">快递</view>
						<view class="box-con-right" v-else-if="item.logisticsType == 1">配送</view>
						<view class="box-con-right" v-else-if="item.logisticsType == 2">快递</view>
						<view class="box-con-right" v-else-if="item.logisticsType == 3">自提</view>
						<view class="box-con-right" v-else-if="item.logisticsType == 4">到店消费</view>
						<view class="box-con-right" v-else-if="item.logisticsType == 5">上门服务</view>
					</view>
					<view class="box-con">
						<view class="box-con-left">下单时间</view>
						<view class="box-con-right">{{ item.createTime }}</view>
					</view>
					<view class="box-con">
						<view class="box-con-left">订单编号</view>
						<view class="box-con-right">{{ item.orderNo }}</view>
					</view>
					
				</view>

				<view class="footer">
					<view class="butt" v-if="item.orderStatus == 6 || item.orderStatus == 7" @tap="del(item)">删除订单</view>
					<!-- <view class="butt">补打小票</view> -->
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { searchOrderList, delOrder } from '../../../utils/api.js';
export default {
	data() {
		return {
			orderList: [],
			search: {
				page: 1,
				size: 10
			},
			show:false,
			orderStatusName:'待处理',
			orderStatusList:[
				[{
					id:8,
					name:'待处理'
				},
				{
					id:9,
					name:'已退款'
				},
				{
					id:10,
					name:'未退款'
				},]
			],
			keyword: '',
			businessId: -1,
			orderStatus: 8,
			list1: [
				{
					name: '申请退款'
				},
				{
					name: '申请售后'
				}
			],
			total:0
		};
	},

	onShow() {
		this.getOrderlist();
	},
	onReachBottom() {
		
		if(this.orderList.length<this.total){
			this.search.page++;
			this.getOrderlist();
		}
		
	},
	methods: {
		searchlist() {
			this.getOrderlist();
			this.keyword = '';
		},
		click(item) {
			// console.log('item', item);
			// this.orderStatus = item.id;
			this.search.page=1;
			this.orderList=[]
			this.getOrderlist();
		},
		confirm(e) {
			console.log(e.value[0].id);
			this.orderStatus = e.value[0].id;
			this.orderStatusName = e.value[0].name;
			this.show = false;
			this.getOrderlist();
		},
		goDetail(item) {
			uni.navigateTo({
				url: '/pages/order/orderDetail/orderDetail?id=' + item.id
			});
		},
		getOrderlist() {
			let data = {
				page: this.search.page,
				size: this.search.size,
				adminId: uni.getStorageSync('userInfo').id,
				userServiceToken: uni.getStorageSync('userInfo').userServiceToken,
				keyword: this.keyword,
				id: 141,
				businessId: this.businessId,
				orderStatus: this.orderStatus
			};

			searchOrderList(data).then(res => {
				if (res.code == 200) {
					if (this.search.page == 1) {
						this.orderList = [];
					}
					let arr = [];
					arr = this.orderList.concat(res.body.list);
					this.orderList = arr;
					this.total=res.body.total

					// businessId.value = "";
					// tableobj.keyword = "";
				}
			});
		},
		del(item) {
			console.log(item);
			let data = {
				ids: item.id
			};
			delOrder(data).then(res => {
				if (res.code == 200) {
					uni.showToast({
						icon: 'none',
						title: '删除成功'
					});
					setTimeout(() => {
						this.getOrderlist();
					}, 500);
				}
			});
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: #f5f5f5;
}
</style>
<style lang="scss" scoped>
.header {
	display: flex;
	align-items: center;
	padding: 20rpx;
	background-color: #fff;
	.button {
		width: 180rpx;
		height: 60rpx;
		.btn {
			color: #fff;
			height: 60rpx;
			line-height: 60rpx;
			font-size: 26rpx;
			background-color: #6da7ff;
			text-align: center;
		}
	}
}
.tags {
	background-color: #fff;
	/deep/.u-tabs__wrapper__nav__item {
		padding: 0 130rpx;
	}
}
.content {
	padding: 20rpx;
	.box {
		background-color: #fff;
		border-radius: 20rpx;
		margin-bottom: 20rpx;
		position: relative;
		padding-bottom: 20rpx;
		.title {
			padding: 40rpx;
			border-bottom: 1rpx solid #f5f5f5;
			.title-con{
				
					width: 100rpx;height: 100rpx;border-radius: 50rpx;
					border: 1rpx solid #999;
					font-size: 26rpx;
					display: flex;
					background-color: #fff;
					align-items: center;
					justify-content: center;
					color: #999;
					font-weight: 700;
					transform: rotate(-30deg);
					position: absolute;
					right: 20rpx;
					top: 30rpx;
					
			}
		}
		.box-con {
			display: flex;

			align-items: center;
			padding: 20rpx 20rpx 0;
			font-size: 26rpx;
			.box-con-left {
				color: #999;
				margin-right: 30rpx;
			}
			.box-con-right {
				color: #1d1e23;
			}
		}

		.footer {
			padding: 20rpx;
			display: flex;
			align-items: center;
			justify-content: flex-end;
			border-top: 1rpx solid #f5f5f5;
			margin-top: 20rpx;
			.butt {
				width: 180rpx;
				height: 50rpx;
				font-size: 26rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				color: #999;
				border: 1rpx solid #999;
				border-radius: 25rpx;
				margin: 0 0 0 30rpx;
			}
		}
	}
}
</style>
